package com.uniview.butterknifedemo;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Lenovo on 2017/4/24.
 */

public class DisplayAdapter extends RecyclerView.Adapter<DisplayAdapter.MyViewHolder> {
    private static final String TAG = DisplayAdapter.class.getSimpleName();

    private Context context;
    private List<String> arrays = new ArrayList<>();

    public DisplayAdapter(Context context, List<String> arrs) {
        this.context = context;
        arrays.addAll(arrs);
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        return null;
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_recycler_view, parent, false);

        MyViewHolder vh = new MyViewHolder(v);

        return vh;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.textView.setText(arrays.get(position));
    }

    @Override
    public int getItemCount() {
        return arrays.size();
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.text)
        TextView textView;

        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
